﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using PPI.Client.Interface;
using PPI.Client.Logic.Utility;
using PPI.Entities.Enumerator;

namespace PPI.Client.Presenter
{
    public class AutolinkPresenter
    {
        private IAutolink m_view;
        private BackgroundWorker m_worker;

        public bool IsReadytoClose
        {
            get { return m_IsReadytoClose; }
        }

        private bool m_IsReadytoClose;

        public AutolinkPresenter(IAutolink m_view)
        {
            this.m_view = m_view;
            m_IsReadytoClose = true;
            m_worker = new BackgroundWorker();
            m_worker.DoWork += new DoWorkEventHandler(m_worker_DoWork);
            m_worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(m_worker_RunWorkerCompleted);
            
        }

        void m_worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            m_IsReadytoClose = true;
            m_view.ChangeDefaultBar();
        }

        void m_worker_DoWork(object sender, DoWorkEventArgs e)
        {
            switch (m_view.DatabaseType)
            {
                case DatabaseTypes.GPS:
                    LUtility_Asset_XMissionStructure.AutolinkVendor(m_view.Distance);
                    break;
                case DatabaseTypes.Inspection:
                    LUtility_Asset_XMissionStructure.AutolinkInspection(m_view.Distance);
                    break;
            }
        }

        public void Execute()
        {
            m_IsReadytoClose = false;
            m_view.ChangeMarqueeBar();
            m_worker.RunWorkerAsync();
        }


    }
}
